/**
 * CustomComponentsService.java
 *
 * Copyright (c) 2009 viorelt All Rights Reserved.
 *
 * This source file may not be copied, modified or redistributed,
 * in whole or in part, in any form or for any reason, without the express
 * written consent of viorelt .
 **/
package ro.prjmanager.service;

import ro.prjmanager.core.service.AbstractService;
import ro.prjmanager.core.service.Service;
import ro.prjmanager.dao.CustomComponentsDao;
import ro.prjmanager.model.CustomComponents;

import java.util.List;

public class CustomComponentsService extends AbstractService<CustomComponents,Integer> implements Service<CustomComponents,Integer> {


    public void delete(Integer id) {
        CustomComponents entity =new CustomComponents();
        entity.setId(id);
        dao.delete(entity);
    }

    public CustomComponents load(Integer id) {
         return dao.find(id,false);
    }

    public List<CustomComponents> listPag(int startPage, int resPerPage) {
          return dao.listPag(startPage, resPerPage);
    }

    public List<CustomComponents> listPag(int startPage, int resPerPage, String orderCol, boolean asc, Object... otherItems) {
        return dao.listPag(startPage, resPerPage,orderCol, asc, otherItems);
    }

    public List<CustomComponents> list() {
        return dao.findAll();
    }

    public List<CustomComponents> listPagFilter(int startPage, int resPerPage, String filter) {
          return dao.listPagFilter(startPage, resPerPage, filter);
    }

    public int no(String filter) {
        return dao.no(filter);
    }

    public void update(CustomComponents entity) {
        CustomComponents customComponentsDb=dao.find(entity.getId(),false);
        if(entity.getComponentDetails()!=null)
            customComponentsDb.setComponentDetails(entity.getComponentDetails());
        if(entity.getFkComponents()!=null)
            customComponentsDb.setFkComponents(entity.getFkComponents());
        if(entity.getFkGroups()!=null)
            customComponentsDb.setFkGroups(entity.getFkGroups());
        if(entity.getFkModel()!=null)
            customComponentsDb.setFkModel(entity.getFkModel());

        dao.update(customComponentsDb);
    }


    public void setDao(CustomComponentsDao dao) {
        this.dao = dao;
    }

    public void create(CustomComponents entity) {
        dao.create(entity);
    }
}
